#ifndef SCENEMANAGER_H
#define SCENEMANAGER_H
#include <QWidget>
#include <QHash>
#include <QDebug>
#include <QTimer>
#include <QElapsedTimer>

class SceneManager{

public:
    static SceneManager& instance(){
        static SceneManager datamanager;
        return datamanager;
    }
    void addScene(int index, QWidget* scene){
        scenes[index] = scene;
    }
    void toNextScene(int nextScene, const QString& message = QString()){
        if(nextScene == -1) exit(0);
        _message = message;
        scenes[nextScene]->show();
        int oldScene = curScene;
        QTimer::singleShot(100, [oldScene, this](){
            if(scenes[oldScene]->close()) qDebug() << "旧窗口成功关闭";
        });
        curScene = nextScene;
    }

    QString _message;
private:
    SceneManager() {timer.start();
                  qDebug() << timer.elapsed();}
    SceneManager(const SceneManager&) = delete;
    QHash<int, QWidget*> scenes;
    int curScene = 0;
    QElapsedTimer timer;
};
#endif // SCENEMANAGER_H
